<!--
    设备状态查询
 -->
<template>
    <div class="page">
        <div class="nuclein-query">
            <div>设备状态查询</div>
            <div style="margin-left: auto;">
                <!-- <el-button type="primary" @click="handlerAdd()">添加</el-button> -->
            </div>
        </div>
        <div class="device-type">
            <span style="margin-left: 20px;">设备类型：</span>
            <el-select v-model="deviceType" placeholder="请选择" clearable>
                <el-option v-for="item in deviceLogType" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
            </el-select>
            <span style="margin-left: 20px;">设备状态：</span>
            <el-select v-model="deviceState" placeholder="请选择" clearable>
                <el-option v-for="item in deviceStates" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
            </el-select>
            <el-button style="margin:20px;" type="primary" @click="handlerAdd()">添加</el-button>
        </div>
        <div class="content-row">
            <el-table :data="tableData" style="width: 100%" border>
                <el-table-column label="设备名称" prop="deviceName">
                </el-table-column>
                <el-table-column label="设备编号" prop="deviceSn">
                </el-table-column>
                <el-table-column label="所在小区" prop="estateName">
                </el-table-column>
                <el-table-column label="所在点位" prop="estateName">
                </el-table-column>
                <el-table-column label="操作时间" prop="acidTime">
                    <template slot-scope="scope">
                        {{ scope.row.operationTime }}
                    </template>
                </el-table-column>
                <el-table-column label="设备服役时长" prop="acidTime">
                    <template slot-scope="scope">
                        {{ scope.row.operationTime }}
                    </template>
                </el-table-column>
                <el-table-column label="设备状态">
                    <template slot-scope="scope">
                        <!-- 报废 -->
                        <el-tag :type="scope.row.operation == 0 ? '' : 'success'">
                            {{ scope.row.operation == 0 ? '正常' : '维修' }}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="设备类型">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.deviceType == 0 ? '' : 'success'">
                            {{ scope.row.deviceType == 0 ? '门禁机' : '室内机' }}
                        </el-tag>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="操作" align="center" width="160">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger"
                            @click="handleDelete(scope.$index, scope.row.id)">删除</el-button>
                    </template>
                </el-table-column> -->
            </el-table>
        </div>

        <div class="pagination">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                :page-sizes="[10, 20, 30, 40]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { getOneList } from '../../api/api'
import commonFunction from '../../utils/commonFunction'
import commonData from '../../utils/commonData'
export default {

  data () {
    return {
      dialogFormVisible: false,
      deviceStates: commonData.deviceState,
      deviceLogType: commonData.deviceLogType,
      total: 10,
      page: 1,
      limit: 10,
      formLabelWidth: '160px',
      tableData: [],
      deviceType: '',
      deviceState: ''
    }
  },
  created () {
    this.gitList()
  },
  methods: {
    // 获取
    gitList () {
      const data = {
        type: 0,
        page: this.page,
        limit: this.limit,
        deviceState: this.deviceState ? his.deviceState : undefined,
        deviceType: this.deviceType ? his.deviceType : undefined
      }
      getOneList({ ...data }).then(res => {
        if (res.code == 0) {
          const { total, list } = res.page
          this.total = total
          this.tableData = list.map(item => {
            const operationTime = commonFunction.getTimeFormat(+new Date(item.operationTime), 'YYYY-MM-DD hh:mm:ss')
            return {
              ...item,
              operationTime
            }
          })
        }
      })
    },
    handlerQuery (e) {
      this.deviceType = e
      this.gitList()
    },
    // 分页
    handleSizeChange (val) {
      this.limit = val
      this.gitList()
    },
    handleCurrentChange (val) {
      this.page = val
      this.gitList()
    }
  }
}
</script>

<style scoped>
.page {
    height: 100%;
}

.nuclein-query {
    display: flex;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #DCDFE6;
}

.content-row {
    overflow: hidden;
}

.device-type {
    padding: 20px 20px 10px 20px;
}

/* 分页 */
.pagination {
    width: 100%;
    padding: 20px;
    border-top: 1px solid #DCDFE6;
}
</style>
